# 3.9 Axis-X&Y Joystick Module ## 3.9.1 Overview Axis-X&Y Joystick is a high-precision input device for bidirectional control. Its X and Y axes are separated to control horizontal and vertical movements respectively. This module contains 10K resistance so that it ensures the stability and accuracy of signals. ## 3.9.2 Schematic Diagram ![t95](./media/t95.png) ESP32 Axis-X&Y Joystick works based on a two-axis potentiometer that detects movements on two axes. When the joystick moves on axis X or Y, the resistance of the potentiometer changes, outputting analog voltage signals. After being received by ESP32 analog input pin (ADC), these signals will be read by ESP32 board and converted to digital values. Therefore, the joystick coordinate can be easily revealed during controlling. ## 3.9.3 Code Blocks Blocks in ![](./media/codingBox.png): 1. ![t96](./media/t96.png) is a block included in coding box library. It reads the X and Y values of the joystick in the coding box. Tap ![](./media/t5.png) to switch: ![t97](./media/t97.png) ## 3.9.4 Test Code You can manually build blocks, or directly open the code file we provide: `3-9-Joystick.ubp`. If you have any questions about how to open code files or upload code, please back to `1.9 Upload Code`. **Build code blocks:** 1. In ![](./media/control.png), drag ![](./media/t1.png) and ![](./media/t2.png) to the script area, and stack them together. ![t34](./media/t34.png) 2. In ![](./media/output.png), drag ![t44](./media/t44.png) block and place in ![](./media/t2.png). 3. Click ![t47](./media/t47.png) of the ![t44](./media/t44.png) to set 4 output blanks in total. In the first blank, enter `X:`; in the third one enter `Y:` ![t98](./media/t98.png) 4. In ![](./media/codingBox.png), drag ![t96](./media/t96.png) block and put it onto the second blank of ![t98](./media/t98.png). 5. In ![](./media/codingBox.png), drag ![t96](./media/t96.png) block and set to Y, and put it onto the fourth blank of ![t98](./media/t98.png). 6. In ![](./media/control.png), drag ![t4](./media/t4.png) block and put it under ![t98](./media/t98.png). Set the delay to `100ms`. **Complete code:** ![t99](./media/t99.png) ## 3.9.5 Test Result Connect the coding box to the MicroBlocks via USB or Bluetooth, and click ![t59](./media/t59.png) to upload the code to the coding box. Toggle the joystick, and the values on axis X and Y changes. ![t100](./media/t100.png)